{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 一、空值处理：删除无用的空值数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "\n",
    "#加载数据集\n",
    "\n",
    "login = pd.read_csv('data/login.csv',encoding='gbk')\n",
    "study_information = pd.read_csv('data/study_information.csv',encoding='gbk')\n",
    "users = pd.read_csv('data/users.csv',encoding='gbk')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>login_time</th>\n",
       "      <th>login_place</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-06 09:32:47</td>\n",
       "      <td>中国广东广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 09:28:28</td>\n",
       "      <td>中国广东广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 09:57:44</td>\n",
       "      <td>中国广东广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 10:55:07</td>\n",
       "      <td>中国广东广州</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>用户3</td>\n",
       "      <td>2018-09-07 12:28:42</td>\n",
       "      <td>中国广东广州</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  user_id           login_time login_place\n",
       "0     用户3  2018-09-06 09:32:47      中国广东广州\n",
       "1     用户3  2018-09-07 09:28:28      中国广东广州\n",
       "2     用户3  2018-09-07 09:57:44      中国广东广州\n",
       "3     用户3  2018-09-07 10:55:07      中国广东广州\n",
       "4     用户3  2018-09-07 12:28:42      中国广东广州"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "login.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>course_id</th>\n",
       "      <th>course_join_time</th>\n",
       "      <th>learn_process</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>用户3</td>\n",
       "      <td>课程106</td>\n",
       "      <td>2020-04-21 10:11:50</td>\n",
       "      <td>width: 0%;</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>用户3</td>\n",
       "      <td>课程136</td>\n",
       "      <td>2020-03-05 11:44:36</td>\n",
       "      <td>width: 1%;</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>用户3</td>\n",
       "      <td>课程205</td>\n",
       "      <td>2018-09-10 18:17:01</td>\n",
       "      <td>width: 63%;</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>用户4</td>\n",
       "      <td>课程26</td>\n",
       "      <td>2020-03-31 10:52:51</td>\n",
       "      <td>width: 0%;</td>\n",
       "      <td>319.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>用户4</td>\n",
       "      <td>课程34</td>\n",
       "      <td>2020-03-31 10:52:49</td>\n",
       "      <td>width: 0%;</td>\n",
       "      <td>299.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  user_id course_id     course_join_time learn_process  price\n",
       "0     用户3     课程106  2020-04-21 10:11:50    width: 0%;    0.0\n",
       "1     用户3     课程136  2020-03-05 11:44:36    width: 1%;    0.0\n",
       "2     用户3     课程205  2018-09-10 18:17:01   width: 63%;    0.0\n",
       "3     用户4      课程26  2020-03-31 10:52:51    width: 0%;  319.0\n",
       "4     用户4      课程34  2020-03-31 10:52:49    width: 0%;  299.0"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "study_information.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>register_time</th>\n",
       "      <th>recently_logged</th>\n",
       "      <th>number_of_classes_join</th>\n",
       "      <th>number_of_classes_out</th>\n",
       "      <th>learn_time</th>\n",
       "      <th>school</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>用户44251</td>\n",
       "      <td>2020/6/18 9:49</td>\n",
       "      <td>2020/6/18 9:49</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>41.25</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>用户44250</td>\n",
       "      <td>2020/6/18 9:47</td>\n",
       "      <td>2020/6/18 9:48</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>用户44249</td>\n",
       "      <td>2020/6/18 9:43</td>\n",
       "      <td>2020/6/18 9:43</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>16.22</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>用户44248</td>\n",
       "      <td>2020/6/18 9:09</td>\n",
       "      <td>2020/6/18 9:09</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>用户44247</td>\n",
       "      <td>2020/6/18 7:41</td>\n",
       "      <td>2020/6/18 8:15</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.80</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   user_id   register_time recently_logged  number_of_classes_join  \\\n",
       "0  用户44251  2020/6/18 9:49  2020/6/18 9:49                       0   \n",
       "1  用户44250  2020/6/18 9:47  2020/6/18 9:48                       0   \n",
       "2  用户44249  2020/6/18 9:43  2020/6/18 9:43                       0   \n",
       "3  用户44248  2020/6/18 9:09  2020/6/18 9:09                       0   \n",
       "4  用户44247  2020/6/18 7:41  2020/6/18 8:15                       0   \n",
       "\n",
       "   number_of_classes_out  learn_time school  \n",
       "0                      0       41.25    NaN  \n",
       "1                      0        0.00    NaN  \n",
       "2                      0       16.22    NaN  \n",
       "3                      0        0.00    NaN  \n",
       "4                      0        1.80    NaN  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "users.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "user_id        0\n",
       "login_time     0\n",
       "login_place    0\n",
       "dtype: int64"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "login.isnull().sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "user_id                0\n",
       "course_id              0\n",
       "course_join_time       0\n",
       "learn_process          0\n",
       "price               4238\n",
       "dtype: int64"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "study_information.isnull().sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "user_id                      67\n",
       "register_time                 0\n",
       "recently_logged               0\n",
       "number_of_classes_join        0\n",
       "number_of_classes_out         0\n",
       "learn_time                    0\n",
       "school                    33412\n",
       "dtype: int64"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "users.isnull().sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>course_id</th>\n",
       "      <th>course_join_time</th>\n",
       "      <th>learn_process</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>用户4</td>\n",
       "      <td>课程51</td>\n",
       "      <td>2020-03-05 16:50:54</td>\n",
       "      <td>width: 0%;</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>用户4</td>\n",
       "      <td>课程96</td>\n",
       "      <td>2019-04-25 14:09:15</td>\n",
       "      <td>width: 0%;</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>138</th>\n",
       "      <td>用户5</td>\n",
       "      <td>课程96</td>\n",
       "      <td>2019-05-27 14:54:47</td>\n",
       "      <td>width: 0%;</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>146</th>\n",
       "      <td>用户5</td>\n",
       "      <td>课程51</td>\n",
       "      <td>2019-08-30 22:04:14</td>\n",
       "      <td>width: 0%;</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>169</th>\n",
       "      <td>用户7</td>\n",
       "      <td>课程96</td>\n",
       "      <td>2019-04-25 14:09:14</td>\n",
       "      <td>width: 0%;</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>189717</th>\n",
       "      <td>用户41626</td>\n",
       "      <td>课程51</td>\n",
       "      <td>2020-06-09 10:00:05</td>\n",
       "      <td>width: 0%;</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>194350</th>\n",
       "      <td>用户44015</td>\n",
       "      <td>课程96</td>\n",
       "      <td>2020-06-12 10:51:46</td>\n",
       "      <td>width: 40%;</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>194353</th>\n",
       "      <td>用户44017</td>\n",
       "      <td>课程51</td>\n",
       "      <td>2020-06-12 10:53:23</td>\n",
       "      <td>width: 0%;</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>194786</th>\n",
       "      <td>用户44126</td>\n",
       "      <td>课程51</td>\n",
       "      <td>2020-06-14 15:36:06</td>\n",
       "      <td>width: 50%;</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>194911</th>\n",
       "      <td>用户44193</td>\n",
       "      <td>课程51</td>\n",
       "      <td>2020-06-16 10:27:11</td>\n",
       "      <td>width: 0%;</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4238 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        user_id course_id     course_join_time learn_process  price\n",
       "9           用户4      课程51  2020-03-05 16:50:54    width: 0%;    NaN\n",
       "36          用户4      课程96  2019-04-25 14:09:15    width: 0%;    NaN\n",
       "138         用户5      课程96  2019-05-27 14:54:47    width: 0%;    NaN\n",
       "146         用户5      课程51  2019-08-30 22:04:14    width: 0%;    NaN\n",
       "169         用户7      课程96  2019-04-25 14:09:14    width: 0%;    NaN\n",
       "...         ...       ...                  ...           ...    ...\n",
       "189717  用户41626      课程51  2020-06-09 10:00:05    width: 0%;    NaN\n",
       "194350  用户44015      课程96  2020-06-12 10:51:46   width: 40%;    NaN\n",
       "194353  用户44017      课程51  2020-06-12 10:53:23    width: 0%;    NaN\n",
       "194786  用户44126      课程51  2020-06-14 15:36:06   width: 50%;    NaN\n",
       "194911  用户44193      课程51  2020-06-16 10:27:11    width: 0%;    NaN\n",
       "\n",
       "[4238 rows x 5 columns]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "studytmp = study_information[study_information['price'].isnull()]\n",
    "studytmp"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 去除\"course_id\"列重复的行数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\soul love\\anaconda3\\lib\\site-packages\\ipykernel_launcher.py:1: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>course_id</th>\n",
       "      <th>course_join_time</th>\n",
       "      <th>learn_process</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>用户4</td>\n",
       "      <td>课程51</td>\n",
       "      <td>2020-03-05 16:50:54</td>\n",
       "      <td>width: 0%;</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36</th>\n",
       "      <td>用户4</td>\n",
       "      <td>课程96</td>\n",
       "      <td>2019-04-25 14:09:15</td>\n",
       "      <td>width: 0%;</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   user_id course_id     course_join_time learn_process  price\n",
       "9      用户4      课程51  2020-03-05 16:50:54    width: 0%;    NaN\n",
       "36     用户4      课程96  2019-04-25 14:09:15    width: 0%;    NaN"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "studytmp.drop_duplicates(subset=['course_id'],keep='first',inplace=True)\n",
    "studytmp"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 将空值填充为0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "user_id             0\n",
       "course_id           0\n",
       "course_join_time    0\n",
       "learn_process       0\n",
       "price               0\n",
       "dtype: int64"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "study_information.fillna(0,inplace=True)\n",
    "study_information.isnull().sum()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 删除“user_id”为空的行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "user_id                       0\n",
       "register_time                 0\n",
       "recently_logged               0\n",
       "number_of_classes_join        0\n",
       "number_of_classes_out         0\n",
       "learn_time                    0\n",
       "school                    33347\n",
       "dtype: int64"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "users.dropna(subset=[\"user_id\"],inplace=True)\n",
    "users.isnull().sum()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 二、异常值处理"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 日期错误：经检查，日期不存在错误"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### users.csv里的“recently_logged”字段的“--”值应该是login.csv里用户的最后一次登录时间，但是在login.csv里没有找到登陆记录，在study_information.csv中能找到该用户的课程记录，因此用购买课程时间进行替换，删除无记录用户"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\soul love\\anaconda3\\lib\\site-packages\\ipykernel_launcher.py:5: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
      "  \"\"\"\n"
     ]
    }
   ],
   "source": [
    "userlist = users[users.recently_logged=='--'].user_id.values\n",
    "for i in userlist:\n",
    "    r1 = study_information[study_information.user_id == i].head(1).course_join_time.values.tolist()\n",
    "    if len(r1)==0:continue\n",
    "    users.recently_logged[users.user_id==i] = r1[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 删除无记录用户"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>register_time</th>\n",
       "      <th>recently_logged</th>\n",
       "      <th>number_of_classes_join</th>\n",
       "      <th>number_of_classes_out</th>\n",
       "      <th>learn_time</th>\n",
       "      <th>school</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: [user_id, register_time, recently_logged, number_of_classes_join, number_of_classes_out, learn_time, school]\n",
       "Index: []"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "deluser = users[users.recently_logged=='--'].index.tolist()\n",
    "users.drop(deluser,inplace=True)\n",
    "users[users.recently_logged=='--']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>register_time</th>\n",
       "      <th>recently_logged</th>\n",
       "      <th>number_of_classes_join</th>\n",
       "      <th>number_of_classes_out</th>\n",
       "      <th>learn_time</th>\n",
       "      <th>school</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>用户44251</td>\n",
       "      <td>2020/6/18 9:49</td>\n",
       "      <td>2020/6/18 9:49</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>41.25</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>用户44250</td>\n",
       "      <td>2020/6/18 9:47</td>\n",
       "      <td>2020/6/18 9:48</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>用户44249</td>\n",
       "      <td>2020/6/18 9:43</td>\n",
       "      <td>2020/6/18 9:43</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>16.22</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>用户44248</td>\n",
       "      <td>2020/6/18 9:09</td>\n",
       "      <td>2020/6/18 9:09</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>用户44247</td>\n",
       "      <td>2020/6/18 7:41</td>\n",
       "      <td>2020/6/18 8:15</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>1.80</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>用户44246</td>\n",
       "      <td>2020/6/17 22:36</td>\n",
       "      <td>2020/6/17 22:36</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>48.92</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>用户44245</td>\n",
       "      <td>2020/6/17 22:16</td>\n",
       "      <td>2020/6/17 22:16</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.18</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>用户44244</td>\n",
       "      <td>2020/6/17 20:59</td>\n",
       "      <td>2020/6/17 21:34</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>用户44243</td>\n",
       "      <td>2020/6/17 20:33</td>\n",
       "      <td>2020/6/17 20:34</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>297.47</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>用户44242</td>\n",
       "      <td>2020/6/17 18:13</td>\n",
       "      <td>2020/6/17 18:13</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   user_id    register_time  recently_logged  number_of_classes_join  \\\n",
       "0  用户44251   2020/6/18 9:49   2020/6/18 9:49                       0   \n",
       "1  用户44250   2020/6/18 9:47   2020/6/18 9:48                       0   \n",
       "2  用户44249   2020/6/18 9:43   2020/6/18 9:43                       0   \n",
       "3  用户44248   2020/6/18 9:09   2020/6/18 9:09                       0   \n",
       "4  用户44247   2020/6/18 7:41   2020/6/18 8:15                       0   \n",
       "5  用户44246  2020/6/17 22:36  2020/6/17 22:36                       0   \n",
       "6  用户44245  2020/6/17 22:16  2020/6/17 22:16                       0   \n",
       "7  用户44244  2020/6/17 20:59  2020/6/17 21:34                       0   \n",
       "8  用户44243  2020/6/17 20:33  2020/6/17 20:34                       0   \n",
       "9  用户44242  2020/6/17 18:13  2020/6/17 18:13                       0   \n",
       "\n",
       "   number_of_classes_out  learn_time school  \n",
       "0                      0       41.25    NaN  \n",
       "1                      0        0.00    NaN  \n",
       "2                      0       16.22    NaN  \n",
       "3                      0        0.00    NaN  \n",
       "4                      0        1.80    NaN  \n",
       "5                      0       48.92    NaN  \n",
       "6                      0        0.18    NaN  \n",
       "7                      0        0.00    NaN  \n",
       "8                      0      297.47    NaN  \n",
       "9                      0        0.00    NaN  "
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "users.head(10)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 学习进度值“learn_process”不利于分析：利用正则表达式获取数字替换字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>user_id</th>\n",
       "      <th>course_id</th>\n",
       "      <th>course_join_time</th>\n",
       "      <th>learn_process</th>\n",
       "      <th>price</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>用户3</td>\n",
       "      <td>课程106</td>\n",
       "      <td>2020-04-21 10:11:50</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>用户3</td>\n",
       "      <td>课程136</td>\n",
       "      <td>2020-03-05 11:44:36</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>用户3</td>\n",
       "      <td>课程205</td>\n",
       "      <td>2018-09-10 18:17:01</td>\n",
       "      <td>63</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>用户4</td>\n",
       "      <td>课程26</td>\n",
       "      <td>2020-03-31 10:52:51</td>\n",
       "      <td>0</td>\n",
       "      <td>319.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>用户4</td>\n",
       "      <td>课程34</td>\n",
       "      <td>2020-03-31 10:52:49</td>\n",
       "      <td>0</td>\n",
       "      <td>299.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  user_id course_id     course_join_time learn_process  price\n",
       "0     用户3     课程106  2020-04-21 10:11:50             0    0.0\n",
       "1     用户3     课程136  2020-03-05 11:44:36             1    0.0\n",
       "2     用户3     课程205  2018-09-10 18:17:01            63    0.0\n",
       "3     用户4      课程26  2020-03-31 10:52:51             0  319.0\n",
       "4     用户4      课程34  2020-03-31 10:52:49             0  299.0"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "study_information['learn_process'] = study_information['learn_process'].str.extract('(\\d+)')\n",
    "study_information.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 查看退出班级数量是否小于加入班级数量，如有，进行删除"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
